package org.psedin.people;

import java.util.ArrayList;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Database {

    public Database() {
    }

    public ArrayList<Usr> getUsers(ArrayList<Long> uNumbers) {
        ArrayList userList = new ArrayList();
        EntityManagerFactory userFactory = Persistence.createEntityManagerFactory("pUnit");
        EntityManager userManager = userFactory.createEntityManager();
        userManager.getTransaction().begin();
        for (Long number : uNumbers) {
            userList.add(userManager.createQuery("from Usr where UNO=" + number).getSingleResult());
        }
        userManager.getTransaction().commit();
        return userList;
    }

    public ArrayList<Sys> getSystems(ArrayList<Long> sysNumbers) {
        ArrayList systemList = new ArrayList();
        EntityManagerFactory userFactory = Persistence.createEntityManagerFactory("pUnit");
        EntityManager userManager = userFactory.createEntityManager();
        userManager.getTransaction().begin();
        for (Long number : sysNumbers) {
            systemList.add(userManager.createQuery("from Sys where SNO=" + number).getSingleResult());
        }
        userManager.getTransaction().commit();
        return systemList;
    }

    public ArrayList<SubSys> getSubSystems(ArrayList<Long> subSysNumbers) {
        ArrayList subSystemsList = new ArrayList();
        EntityManagerFactory userFactory = Persistence.createEntityManagerFactory("pUnit");
        EntityManager userManager = userFactory.createEntityManager();
        userManager.getTransaction().begin();
        for (Long number : subSysNumbers) {
            subSystemsList.add(userManager.createQuery("from SubSys where SNO=" + number).getSingleResult());
        }
        userManager.getTransaction().commit();
        return subSystemsList;
    }
}
